<?php

/**
 * Description of ScannerController
 *
 * @author Thomas Vo
 */
class ScannerController extends BRController
{
    public function filters()
    {
        return array(
            'accessControl',
        );
    }
    
    public function accessRules() 
    {
        return array(
            array('deny',
                'users'=>array('?'),
            ),
        );
    }
    
    public function actionIndex()
    {
        $scannerForm  = new ScannerForm();
        $searchResult = null;
        if(isset($_GET['barcode']))
        {
            $barcode      = $_GET['barcode'];
            $searchResult = $scannerForm->scan($barcode);
        }
        else if(isset($_POST['ScannerForm']))
		{
			$scannerForm->attributes = $_POST['ScannerForm'];
			$searchResult = $scannerForm->scan();
		}
        
        $this->renderPartial('index',array('scannerForm'=>$scannerForm,'searchResult'=>$searchResult));
    }
    
    public function actionGetConfig()
    {
        $home       = urldecode($this->createAbsoluteUrl('scanner'));
        $lookup     = urlencode($this->createAbsoluteUrl('scanner', array('barcode'=>'CODE')));
        $configLink = 'p2spro://configure?lookup='.$lookup.'&home='.$home;
        $this->renderText(CHtml::link('Configure pic2shop now.', $configLink));
    }
    
    public function actionLookUpASIN()
    {
        if(!(isset($_REQUEST['asin'])))
            return;
        $asin = $_REQUEST['asin'];
    }
}

?>
